[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
assert() Diagnostic Message Generator
#include <assert.h>
#include <stdio.h>
void assert(expression); condition to be evaluated.
int expression;
assert() tests 'expression'. If 'expression' fails, assert() prints a
diagnostic message and aborts the calling process. No action is
taken if 'expression' is true (nonzero), so 'expression' should be
chosen so it is true if the program is operating correctly.
The diagnostic message has the form:
Assertion failed: 'expression', file 'filename', line 'linenumber'
where 'filename' is the source file name and 'linenumber' is the line
where assert() appears. assert() is used to identify program logic
errors.
Returns: No return value
Notes: assert() is a macro.
If NDEBUG is defined (with any value), the C
preprocessor removes all assert() calls from the
program. NDEBUG can be defined via the -D command-
line option, or with a #define directive.
-------------------------------- Example ---------------------------------
The following statement tests whether pshift is NULL and prints an
appropriate message.
#include <assert.h>
#include <stdio.h>
struct BASE {
char *name;
int number;
} *pshift;
main()
{
assert(pshift != NULL);
/* process item */
}
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson